Drop Database



MySQL - Drop Database


DROP TABLE in MySQL statement allows you to remove or delete a table from the MySQL database.


SYNTAX :
DROP TABLE table_name;

However, the full syntax for the MySQL DROP TABLE statement is:


DROP [ TEMPORARY ] TABLE [ IF EXISTS ]
table_name1, table_name2, ...
[ RESTRICT | CASCADE ];

Parameters or Arguments :


  • TEMPORARY - Optional. It specifies that only temporary tables should be dropped by the DROP TABLE statement.

  • table_name - The name of the table to remove from the database.

  • table_name1, table_name2 - The tables to remove from the database, if removing more than one table in the DROP TABLE statement.

  • IF EXISTS - Optional. If specified, the DROP TABLE statement will not raise an error if one of the tables does not exist.

  • RESTRICT - Optional. It has no impact or effect on the DROP TABLE statement but is included in the syntax to make porting the tables to different databases easier.

  • CASCADE - Optional. It has no impact or effect on the DROP TABLE statement but is included in the syntax to make porting the tables to different databases easier.


    Note : If you use the MySQL DROP TABLE statement to drop one or more tables that do not exist, the database will raise an error (unless you specify the IF EXISTS parameter in the DROP TABLE statement).


    Example :

    Let's look at an example that shows how to drop a table using the MySQL DROP TABLE statement.


    Drop One Table :

    First, let's look at a simple DROP TABLE example that shows how to use the DROP TABLE statement to drop one table in MySQL.


    DROP TABLE customers;
    

    As a result,Customers table gets deleted.


    Drop Multiple Tables :

    Let's look at an example where we want to drop more than one table using the DROP TABLE statement:


    DROP TABLE customers, suppliers;
    

    This DROP TABLE statement example would delete two tables - customers and suppliers. If we were worried that one of the tables doesn't exist and we don't want to raise an error, we could modify our DROP TABLE statement as follows:


    DROP TABLE IF EXISTS customers, suppliers;
    
    

    This example would delete the customers and suppliers tables and would not raise an error if one of the tables didn't exist.


    Drop Temporary Table :

    Finally, let's look at an example that shows how to use the DROP TABLE statement to drop a temporary table.

    DROP TEMPORARY TABLE IF EXISTS customers;
    
    

    This DROP TABLE example will only delete the temporary table called customers. If there was also a permanent table called customers, this DROP TABLE statement would not delete it because TEMPORARY is specified.



    MySQL TRIGGERS

    MySQL - Triggers

    posted on 2019-11-29 21:44:07 - mysql Tutorials


    Grant_ Revoke Privilege

    MySQL - Grant_ Revoke Privilege

    posted on 2019-11-26 23:15:04 - mysql Tutorials


    MySQL Vs SQL

    MySQL Vs SQL

    posted on 2019-11-25 05:02:26 - mysql Tutorials


    Prompt Examples

    ChatGPT Prompt Examples

    posted on 2023-06-21 22:37:19 - ChatGPT Tutorials


    Use Cases

    Chat GPT Key Use Cases

    posted on 2023-06-21 21:03:17 - ChatGPT Tutorials


    Prompt Frameworks

    Prompt Frameworks

    posted on 2023-06-21 19:33:06 - ChatGPT Tutorials